package com.twu.biblioteca;

import java.util.HashMap;
import java.util.SortedSet;
import java.util.TreeSet;

public class MenuState implements State {

    public static MenuState instance = new MenuState();

    HashMap<String, State> statesHash = new HashMap<String, State>();

    private MenuState() {
        statesHash.put("1", ListBooksState.instance);
        statesHash.put("2", ReserveBooksState.instance);
        statesHash.put("3", ListMoviesState.instance);
        statesHash.put("4", MembershipState.instance);
        statesHash.put("5", LoginState.instance);

    }

    @Override
    public String getMessage() {
        String menuList = "";
        SortedSet<String> keys = new TreeSet<String>(statesHash.keySet());

        for (String key : keys) {
            menuList = menuList + key + "\t" + statesHash.get(key).getMenuOption() + "\n";
        }

        return menuList;
    }

    @Override
    public String getMenuOption() {
        return "Main Menu";
    }

    @Override
    public State change(String input) {
        if (statesHash.containsKey(input))
            return statesHash.get(input);
        else
            return MenuState.instance;
    }
}
